package tt;

import java.util.Scanner;

public class Fourth {
    public static void main(String[] args) {
        fourth();
    }
    public static void fourth() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[i] = scanner.nextInt();
        }
        if(n>10000){
            System.out.println(0);
            return;
        }
        int[][] ap = new int[n][n];
        int[][] bp = new int[n][n];
        for (int i = 0; i < n; i++) {
            ap[i][i] = a[i];
            bp[i][i] = b[i];
        }
        for (int i = 0; i < n; i++) {
            int max = ap[i][i];
            int min = bp[i][i];
            for (int j = i; j < n; j++) {
                if (a[j] > max) {
                    ap[i][j] = a[j];
                    max = a[j];
                } else {
                    ap[i][j] = max;
                }
                if (b[j] < min) {
                    bp[i][j] = b[j];
                    min = b[j];
                } else {
                    bp[i][j] = min;
                }
            }
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (ap[i][j] < bp[i][j]) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}
